package core;

//This abstract class is made for Turn Based Board games.

public abstract class GameAbs {
	protected PlayerAbs[] players;
	protected int currentPlayerIndex;

	public void reset() {
		currentPlayerIndex = 0;
		for (int i = 0; i < players.length; i++) {
			players[i].reset();
		}
	}

	public PlayerAbs[] getPlayers() {
		return players;
	}

	public int getNumberOfPlayers() {
		return players.length;
	}

	public PlayerAbs getCurrentPlayer() {
		return players[currentPlayerIndex];
	}

	public boolean isLastPlayer() {
		return currentPlayerIndex == 0;
	}

	public void nextPlayer() {
		this.currentPlayerIndex++;
		// this.currentPlayerIndex %= this.players.length;
	}

	public PlayerAbs[] getVictoryPlayers() {
		PlayerAbs[] victoryPlayers = new PlayerAbs[players.length];
		int index = 0;
		for (int i = 0; i < players.length; i++)
			if (players[i].isVictoryState()) {
				victoryPlayers[index] = players[i];
				index++;
			}
		PlayerAbs[] trimedArray = new PlayerAbs[index];

		for (int i = 0; i < trimedArray.length; i++)
			trimedArray[i] = victoryPlayers[i];

		return trimedArray;
	}

}
